<%@page import="com.MD5"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    
    <%@page import="com.DBtools"%>
    <%@ page import="java.sql.*" %>
    
    <!--这是一个密码修改页面  -->
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<%@ include file="../bootstrap.jsp"%>
<title>修改密码</title>
</head>
<style> .yanz{color:gray;font-size:12px;} </style>
<%
//接收教师账号修改信息
request.setCharacterEncoding("UTF-8");
String UserNum=null;


String orinpwd=(String) request.getSession().getAttribute("UserPwd");
UserNum=(String) request.getSession().getAttribute("UserNum");


String NewPwd=request.getParameter("NewPwd"); 

 if(NewPwd!=null)  NewPwd=new MD5().md5(NewPwd);//加密算法

String UserPwd=request.getParameter("UserPwd");

String sql="";
String num="";

if(NewPwd!=null &&UserPwd.equals(orinpwd)){

	sql = "update user set UserPwd='"+NewPwd+"' where UserNum ='"+UserNum+"'";
	int	r = new DBtools().execute(sql);
	System.out.println("修改成功");
	response.sendRedirect("../Loginout.jsp");
}

//out.println("sql="+sql+"<br>");	
 %>
<body>
<h1 align=center>修改账号密码</h1>
<hr>
<!-- 修改账号密码 -->
<br>
<form name="inputacc">
<table width="600"  height="400" align="center" border="1" class="imagetable">
<tr >
     <th height="50" colspan="2"  class="p-3 mb-2 bg-primary text-white"></th>
        
  </tr>
<tr >
<td class="p-3 mb-2 bg-light text-dark">账号</td>
<td><input class="form-control" name="TeaId"  id="TeaId" value="<%=UserNum%>" readonly></td>
</tr>
<tr hidden="hidden">
<td></td>
<td><input name="orinpwd"  id="orinpwd" value="<%=orinpwd%>"></td>
</tr>
<tr>
<td width=100 class="p-3 mb-2 bg-light text-dark">原密码</td>
<td><input  class="form-control"type="password" name="UserPwd"  id="UserPwd" ></td>
</tr>

<tr>
<td width=100 class="p-3 mb-2 bg-light text-dark">新密码</td>
<td><input class="form-control" type="password" name="NewPwd"  id="NewPwd" placeholder="密码位数在6~10之间">
</td>
</tr>
<tr>
<td width=140  class="p-3 mb-2 bg-light text-dark">再次输入密码</td>
<td><input class="form-control" type="password" name="ReNewPwd"  id="ReNewPwd" placeholder="请与新密码保持一致">
</td>
</tr>
<tr align="center">
<td colspan="2"><input type="submit" name="btn"  value="注册" id="btn1" onclick="return check1(this.form)" style="display:none">
<input width=70 height=40 class="btn btn-primary" type="submit" name="btn" value="修改" id="btn2" onclick="return check2(this.form)" ></td>

</tr>
 </table>
 </form>
</body>
<script type="text/javascript">

var ReNewPwd =document.querySelector("ReNewPwd");
var NewPwd= document.querySelector('input');

//var input = document.querySelector('NewPwd')
var men = document.querySelector('.yanz')
input.onfocus = function() {
    if (NewPwd.value.length<6) {
    	NewPwd.value = ''
    }
}
input.onblur = function() {
    if (NewPwd.value == '') {
    	NewPwd.style.border = '1px solid red'
        men.innerHTML = '请输入正确的手机号码'
        men.style.color = 'red'
    }
}


   function check2(form){
	   /* var TeaId= document.getElementById("TeaId").value; */
	   /*  var btn1= document.getElementById("btn1").value; */
	   /*  var btn2= document.getElementById("btn2").value; */
	  /*  alert(btn1); */
	   //alert(pwd);
	   
	  // var UserPwd=(String) request.getSession().getAttribute("UserPwd");
	    var ReNewPwd =document.getElementById("ReNewPwd").value;
       var NewPwd= document.getElementById("NewPwd").value; 
       var orinpwd= document.getElementById("orinpwd").value;
       var UserPwd= document.getElementById("UserPwd").value;
	   var btn2=document.inputacc.btn2.value;
	  // alert(btn2);
	   
	   	if(UserPwd!=orinpwd){
		   alert("原密码错误，请重新输入！");
		   document.inputacc.UserPwd.focus();
		   return false;
		   }
	   	else if(ReNewPwd.length<6 ||NewPwd !==ReNewPwd){
				   alert("密码不合法或不一致");
				   document.inputacc.ReNewPwd.focus();
				   document.inputacc.NewPwd.focus();
				   return false;
			   		} 
			   
	   /* 	else if(pwd.length <=0){   
	   	 	alert("该教师账号尚未注册，请先注册！");
		   	return false;
	   	} */
	   	else {
	   	 	alert("修改成功！");
	   		return true;
	   	}
	
	   
   	}

   
 

</script>


</body>
</html>